<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script src="/js/vue/vue.min.js"></script>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/laypage/laypage.js"></script>
    <script src="/js/layer/layer.js"></script>
</head>
<body>
<style>
    .admin{
        float: right;
    }
</style>
<body>
<div id="app" class="container">
    <span class="admin">欢迎用户${admin.adminName}</span>
    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">题库名称</label>
            <input type="text" class="form-control" id="username" placeholder="题库名称">
        </div>
        <button type="button" id="findLib" class="btn btn-success">查询题库</button>
        <button type="button" id="addLibBtn" class="btn btn-danger">增加题库</button>
    </form>

    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>题库名称</td>
                <td>题库描述</td>
                <td>题库人</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.lib_name}}</td>
                <td>{{item.lib_desc}}</td>
                <td>{{item.teacher.teacher_name}}</td>
                <td><a href="#" @click="editEvent(item.id)">编辑</a> <a href="#" @click="delEvent(item.lib_id)">删除</a></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<script>
    var app = new Vue({
        el:'#app',
        data:{
            result:[]
        }
    });
    var getLibList = function (curr) {
        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/lib/getPage.do',
            data:{
                pageNum:curr||1,
                pageSize:3,
                lib_name:$("#username").val()
            },
            success:function (msg) {
                app.result=msg.page;
                laypage({
                    skin:'#40E0D0',
                    cont:'pagenav',
                    pages:msg.totalPage,
                    curr:curr||1,
                    jump:function (obj,first) {
                        if(!first){
                            getLibList(obj.curr);
                        }
                    }
                });
            }
        });
    }
    getLibList();
    //根据用户查找用户
    $("#findLib").click(function () {
        getLibList();
    });

    //添加用户
    $("#addLibBtn").click(function () {
        layer.open({
            type:2,
            title:'添加用户',
            fix:false,
            maxmin:true,
            shadeColse:true,
            area:['900px','600px'],
            content:'/lib/toAddLib.do',
            dataType:"json",
            end:function (data) {
                getLibList();
            }
        });
    });

    //编辑
    var editEvent = function (id) {
        layer.open({
            type:2,
            title:'编辑用户',
            fix:false,
            maxmin:true,
            shadeColse:true,
            area:['600px','400px'],
            content:'/lib/toUpadteLib.do?id='+id,
            end:function () {
                getLibList();
            }
        });
    }
    var delEvent = function (id) {
        layer.confirm("确定要删除吗？",{
            bth:['是','否']},function () {
            $.ajax({
                type:'GET',
                dataType:'json',
                url:'/lib/delLib.do',
                data:{
                    "lib_id":id,
                },
                success:function () {
                    getLibList();
                    layer.msg("已经删除了id为" + id + "的记录", {icon: 2});
                }
            });
        });
    }
</script>
</body>
</html>